home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
11587
/
11587.xpi
/
chrome
/
aviary.jar
/
content
/
pearlutil-request.js
< prev
next >
Wrap
Text File
|
2009-07-08
|
3KB
|
81 lines
/* Copyright (c) 2008-2009 Pearl Crescent, LLC. All Rights Reserved. */
/* vim: set sw=2 sts=2 ts=8 et syntax=javascript: */
/*
* This file is part of the Pearl Crescent Utility Functions Library.
*
* Notes for use in projects:
* + This object is needed to address "regressions" in Firefox where
* cookies are not always sent with XMLHttpRequests. It offers
* compatibility across Firefox 3.0, 3.5 and beyond.
*/
if (!com) var com = {};
if (!com.aviary) com.aviary = {};
if (!com.aviary.talon) com.aviary.talon = {};
if (!com.aviary.talon.request)
com.aviary.talon.request = {
// aChannel should be an nsIChannel.
// aBackupWin is optional. If present, it should be a brower window. It
// is used in Firefox 3.5 to obtain the loadGroup for retrieving cookies
// if no other browser windows can be located.
EnsureCookiesWillBeSent: function(aChannel, aBackupWin)
{
if (!aChannel)
return;
const kCC = Components.classes;
const kCI = Components.interfaces;
if ((aChannel instanceof kCI.nsIHttpChannelInternal)
&& ("forceAllowThirdPartyCookie" in aChannel))
{
aChannel.forceAllowThirdPartyCookie = true;
}
else
{
// Set loadGroup and loadFlags so that cookies are sent when
// pref for "Send 3rd Party Cookies" is not set.
// This is a work around for Mozilla bug # 437174.
try
{
var docShell;
var appInfoSvc = kCC["@mozilla.org/xre/app-info;1"]
.getService(kCI.nsIXULAppInfo);
var platformVer = appInfoSvc.platformVersion;
var verCmpSvc = kCC["@mozilla.org/xpcom/version-comparator;1"]
.getService(kCI.nsIVersionComparator);
var haveGecko191 = (verCmpSvc.compare(platformVer, "1.9.1b1") >= 0);
if (haveGecko191) // FF >= 3.5
{
var wm = kCC["@mozilla.org/appshell/window-mediator;1"]
.getService(kCI.nsIWindowMediator);
var browserWin = wm.getMostRecentWindow("navigator:browser");
if (!browserWin)
browserWin = aBackupWin;
docShell = browserWin.QueryInterface(kCI.nsIInterfaceRequestor)
.getInterface(kCI.nsIWebNavigation)
.QueryInterface(kCI.nsIInterfaceRequestor);
}
else // FF 3.0.x
{
docShell = kCC["@mozilla.org/webshell;1"]
.createInstance(kCI.nsIDocShellTreeItem)
.QueryInterface(kCI.nsIInterfaceRequestor);
docShell.itemType = kCI.nsIDocShellTreeItem.typeContent;
}
if (docShell)
aChannel.loadGroup = docShell.getInterface(kCI.nsILoadGroup);
}
catch(e) { dump("EnsureCookie err: " + e + "\n"); }
aChannel.loadFlags |= aChannel.LOAD_DOCUMENT_URI;
}
},
endOfObject: true
}